package com.wx.util;

import java.io.IOException;

import org.json.JSONException;

import com.github.qcloudsms.SmsSingleSender;
import com.github.qcloudsms.SmsSingleSenderResult;
import com.github.qcloudsms.httpclient.HTTPException;

public class qcloudSMSUtil { 
	// 短信应用SDK AppID
	private final int appid = 1400153960; 
	// 短信应用SDK AppKey
	private final String appkey = "2f9857ffa5e663933ff9f1f1adc4c3a4"; 
	// 短信模板ID
	private final int templateId = 217368; 
	// 签名
	private final String smsSign = "开发实践公号"; 

	public void sendSMSCheckCode(String telephone, String checkCode, String eTime) {
		String[] str = new String[2];
    	str[1] = checkCode;
    	str[2] = eTime;
		
    	// 单发短信
        try {
            SmsSingleSender ssender = new SmsSingleSender(appid, appkey);
            SmsSingleSenderResult result = ssender.sendWithParam("86", telephone, templateId, str, smsSign, "", "");
            System.out.print(result);
        } catch (HTTPException e) {
            // HTTP响应码错误
            e.printStackTrace();
        } catch (JSONException e) {
            // json解析错误
            e.printStackTrace();
        } catch (IOException e) {
            // 网络IO错误
            e.printStackTrace();
        }
	}
}
